The string Formatting is a method to display the variable value inside string. the python provides the four ways to forming the string . that shown in the below .the string formatting is a way to displaying string inside variable value.
This are the ways to forming the string in side the variable values
it is a old way to forming the string in the variable value . like in c programming when we are using %d to format the sting same way but some difference. Examples shown in the below
name="darshan"
print('The %s is a web developer')
Output:- The darshan is a web developer
age=19
print( 'The developer age is %d '%(age))
Oputput:- The devloper age is 19
salary=20000.00
print("The developer salary is %f"%(salary))
Output:- The developer salary is 20000.000
The string Format is a process of displaying the variable value inside the string by using the .Format() method . there is a two parts position and keyword
Position means index value place of the variable can displaying inside the curly braces{0}. keyword is a value give in the same line
Example in the below
name='hemanth'
age=20
print('The {0} is {1} years old'.format(name,age))
print('The {name} is{age} years old'.format(name="Tharun",20))
Output:- The Tharun is 20 years old
This method is latest version 3.6 and simple way to forming the variable value inside the string Examples in the below and the variable name inside the string with curly braces
name="Nandini"
print(f'The{name} is a good friend of me )
output:-The Nandini is a good friend of me
this is useful for expert programmers . import some class and using the value. no examples